<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户管理</title>
    <link rel="shortcut icon" type="image/x-icon" href="../../favicon.ico"/>
    <link rel="stylesheet" href="../../layui/css/layui.css">
    <link rel="stylesheet" href="../../css/common.css">

    <link rel="stylesheet" href="../../layui/extend/dtree.css">
    <link rel="stylesheet" href="../../layui/extend/font/dtreefont.css">

    <!-- 图标 -->
    <link rel="stylesheet" href="../../static/CaoMei/style.css">
</head>

<body>

<div class="yadmin-body animated fadeIn">
    <form class="layui-form yadmin-search-area input" action="/ordGoods/selectList">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label for="visiterName" class="layui-form-label">用户名</label>
                <div class="layui-input-inline">
                    <input type="text" name="visiterName" autocomplete="off"
                           id="visiterName" class="layui-input">
                </div>

                <label for="goodsName" class="layui-form-label">商品名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="goodsName" autocomplete="off"
                           id="goodsName" class="layui-input">
                </div>



                <button type="button" data-type="reload"
                        class="layui-btn">
                    <i class="layui-icon layui-icon-search"></i>
                </button>
            </div>
        </div>
    </form>

    <table class="layui-hide" id="orderGoods-table" lay-filter = "orderGoods-table"></table>
</div>

<script type="text/html" id="toolbar">

    <!--<button type="submit" class="layui-btn layui-btn-xs layui-btn-normal" lay-event="add">-->
    <!--<i class="layui-icon layui-icon-addition"></i>-->
    <!--新增-->
    <!--</button>-->

</script>

<script type="text/html" id="column-toolbar">

    <!--<button type="button" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">-->
        <!--<i class="layui-icon layui-icon-edit" title="完成"></i>-->
        <!--完成-->
    <!--</button>-->

    <button type="button" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">
        <i class="layui-icon layui-icon-delete" title="删除"></i>
        删除
    </button>


</script>


I
<script src="../../js/jquery.js"></script>
<script src="../../layui/layui.js"></script>
<script src="../../js/common.js"></script>

<script>
    layui.config({
        base: '/layui/extend/'
    }).use(['laydate', 'element', 'form', 'table','layer','dtree', 'tablePlug'], function () {
        var table = layui.table;
        var laydate = layui.laydate;
        var $ = layui.jquery;
        var form = layui.form;
        var dtree = layui.dtree;
        var tablePlug = layui.tablePlug;


        table.render({
            elem: '#orderGoods-table',
            url: '/ordGoods/selectList',
            page: true,
            toolbar: '#toolbar',
            smartReloadModel: true,
            response:{
                statusName: 'code', //数据状态的字段名称，默认：code
                statusCode: 0, //成功的状态码，默认：0
                countName: 'count', //数据总数的字段名称，默认：count
                dataName: 'data' //数据列表的字段名称，默认：data
            },
            cols: [
                [
                    {type: 'numbers', title: '序号', width: 60},
                    {field: 'id', title: 'ID', hide: true},
                    {field: 'visiterName', title: '用户名', minWidth: 80},
                    {field: 'goodsName', title: '商品名称', minWidth: 80},
                    {field: 'createTime', title: '创建时间', align: 'center', width: 180},
                    {field: 'number', title: '数量',align: 'center', width: 80},
                    {field: 'price', title: '价格',align: 'center', width: 80},
                    {field: 'total', title: '总价',align: 'center', width: 80},
                    {field: 'address', title: '地点',align: 'center', width: 80},
                    {title: '操作', fixed: 'right', align: 'center', toolbar: '#column-toolbar'}
                ]
            ],
            id:"orderGoods-table",
            // done: function (res,curr,count) {
            //     $("[data-field='damage']").children().each(function(){
            //         if($(this).text()=='0'){
            //             $(this).text("设备损坏")
            //         }else if($(this).text()=='1'){
            //             $(this).text("设备正常")
            //         }
            //     })
            //
            //
            // },

            limit:5,
            page:{
                layout:['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
                ,limits:[5,10,15]
                ,first:false
                ,last:false
            },
            skin:'line'
        });




        //监听用户名搜索事件

        var active = {
            reload: function(){
                var visiterName = $('#visiterName');	//得到搜索框里已输入的数据
                var goodsName = $('#goodsName');	//得到搜索框里已输入的数据
                //执行重载
                table.reload('orderGoods-table', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        visiterName:  visiterName.val(),
                        goodsName:goodsName.val(),//在表格中进行搜索
                    }
                });
            }
        };

        $('.layui-inline .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });




        // 行点击事件
        table.on('tool', function (obj) {
            var data = obj.data;
            var event = obj.event;
            if (event === 'edit') {
                edit(data);
            } else if (event === 'del') {

                layer.confirm("确定删除角色吗?", {icon: 3, title: '提示'},
                    function (index) {// 确定回调
                        $.ajax({
                            url: "/ordGoods/delete/"+data.id,    //这个是后台的路由地址
                            type: "POST",
                            // data:{"id":data.id},//传给后台的值
                            dataType: "json",
                            success: function(data){
                                if(data['code']==0){   //从前台取回的状态值
                                    layer.close(index);
                                    //同步更新表格和缓存对应的值
                                    obj.del();
                                    layer.msg("删除成功", {icon: 6});
                                }else{
                                    layer.msg("删除失败", {icon: 5});
                                }
                            }
                        });
                        layer.close(index);
                        table.reload('orderWaiter-table');
                    }, function (index) {//取消回调
                        layer.close(index);
                    }
                );

            }
        });

        //
        // function edit(data) {
        //     var sta ;
        //
        //     console.log("aaaa"+data.state);
        //     if (data.state == 1 ){
        //         sta = 1;
        //     } else sta = 0;
        //     layer.open({
        //         content: '/ordEqu/upDamage/' + "id="+ data.id+'&state='+sta,
        //         title: "完成",
        //         area: ['40%', '85%'],
        //         type: 2,
        //         maxmin: true,
        //         shadeClose: true,
        //
        //         end: function () {
        //             table.reload('orderGoods-table');
        //         }
        //     });
        // };
        // //


    });
</script>
</body>
</html>